package com.code.day04_utiles;

import com.code.utils.DruidUtils;
import org.junit.Test;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

public class Demo02Batch {

    @Test
    public void batch() throws SQLException {
        Connection conn = DruidUtils.getConnection();
        String sql = "insert into `category`(cname) values(?)";
        PreparedStatement ptst = conn.prepareStatement(sql);

        for (int i = 0; i < 100; i++) {
            ptst.setObject(1,"java"+i);
            ptst.addBatch();
        }
        ptst.executeBatch();


        DruidUtils.closeConnection(conn,ptst,null);

    }
}
